package com.pingan.haofang.searchcloud.api.query.parser.dbobject.sqlnode.aggregate;

import com.pingan.haofang.searchcloud.api.query.parser.dbobject.FunctionConfig;

/**
 * ClassName: Max <br>
 * Function:
 *
 * @author luyi
 * @version 1.0.0
 * @since 1.0.0
 * @date 20150816
 */
public class Max extends AggregateFunction {

    private static final int VALUE_PARAM_COUNT = 2;

    public Max() {
        setName(FunctionConfig.MAX.name);
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public Object getValue(Object...params) {
        assertParamCount(params, VALUE_PARAM_COUNT);
        assertParamType(params, Comparable.class);
        if (((Comparable) params[0]).compareTo((Comparable) params[1]) >= 0) {
            return params[0];
        } else {
            return params[1];
        }
    }

    @Override
    public int getParamCount() {
        return 1;
    }

}
